<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <title>商户注册管理</title>
        
           <link rel="stylesheet" type="text/css" href="../css/cm-default.css"  />
        <link rel="stylesheet" type="text/css" href="../ligerUI/skins/Aqua/css/ligerui-all.css" />
        <link rel="stylesheet" type="text/css" href="../ligerUI/skins/ligerui-icons.css" />
        <script src="../js/jquery-min.js" type="text/javascript"></script>
        <script src="../ligerUI/js/ligerui.min.js" type="text/javascript"></script>
        <script src="../js/common.js" type="text/javascript"></script>
        <script src="../js/json2.js" type="text/javascript"></script>
        <script type="text/javascript" src="../js/md5.js"></script>
        <script src="../js/validate/jquery.validate.js" type="text/javascript"></script>
        <script src="../js/validate/jquery.metadata.js" type="text/javascript"></script>
        <script src="../js/validate/messages_zh.js" type="text/javascript"></script>
        <script type="text/javascript">
            var defGrid,opt,addDialog,modifyDialog,shopNo;
            var query = getQueryString(window.location.toString());
            opt = query.m;
            $(function(){
                defGrid = $("#query_list").ligerGrid({
                    columns:[
                        {display:'操作',isSort:false,width:130,render:function(rowdata,rowindex,value) {
                             
                            var h = ""; 
                            var row = defGrid.getRow(rowindex);
                              if(row.shop_useable == '0' )
                                {                                 
                                  h += "<a href='javascript:void(0);' id='toConfirm' class='opt-link' onclick='toConfirm(" + rowindex + ")'>审核</a> ";
                                }
                              if(row.shop_useable  == '1') 
                                {
                                  h += "已审核  ";
                                }
                            return h; 
                        },frozen:true
                        },
                        {display:'单据状态',name:'shop_useable',width:70,minWidth:60,render:function(item){return paramRender(item,'shop.status',item.shop_useable);}},
                        {display:'商户名称',name:'shop_name',width:100},
                        {display:'商户账户',name:'shop_no',width:100},
                        {display:'商户地址',name:'shop_address',width:150,render:function(rowdata,rowindex,value){if(value=='null')value='';return value}},
                        {display:'协议编号',name:'agreed_no',width:100},
                        {display:'协议签订日期',name:'agreed_date',width:100},
                        {display:'账户有效期',name:'agreed_term',width:100},
                        {display:'商户密码',name:'wifi_pwd',width:120,minWidth:60,align:'left',render:function(rowdata,rowindex,value){
                            return "<a href='javascript:void(0);' class='opt-link' onclick='open_Modfiy_PW(" + rowindex + ")'>重置密码</a>";}},
                        {display:'是否有效',name:'shop_useable',width:100,render:function(item){return paramRender(item,'rbac.status',item.shop_useable);}},
                        {display:'备注说明',name:'shop_note',width:200}
                    ],
                    pageSize:20,
                    usePager: true,
                    dataAction:'server', 
                    url: '../common/q.jsp', 
                    width:'100%',
                    height:'99%',
                    dataAction:'server',
                    checkbox:false,
                    rownumbers:false,
                    fixedCellHeight:false,
                    colDraggable:true,
                    enabledEdit:true,
                    clickToEdit:false,
                    onDblClickRow:searchRow,  //双击查询
                    onSelectRow:function(rowdata, rowindex){$("#txtrowindex").val(rowindex);},
                    onReload: toQuery,
                  //第一页
                    onToFirst: function(item) {
                        toQuery(item, 1);
                    },
                    //最后一页
                    onToLast: function(item) {
                        var p = parseInt(defGrid.options.total / defGrid.options.pageSize);
                        if (defGrid.options.total % defGrid.options.pageSize > 0)
                            p += 1;
                        toQuery(item, p);
                    },
                    //上一页
                    onToPrev: function(item) {
                        var p = parseInt(defGrid.options.page);
                        if (p > 1)
                            p -= 1;
                        else
                            return;
                        toQuery(item, p);
                    },
                    //下一页
                    onToNext: function(item) {
                        var p = parseInt(defGrid.options.total / defGrid.options.pageSize);
                        if (defGrid.options.total % defGrid.options.pageSize > 0)
                            p += 1;
                        var cp = parseInt(defGrid.options.page); 
                        if (cp < p)
                            cp += 1;
                        toQuery(item, cp);
                    }
                });
                    appendAddBtn(openDictDef, "新增商户信息");
                    appendBtnForGridToolbar("l-bar-btnwifi", "l-icon-wifi", addWifi,"添加wifi信息");
                    appendBtnForGridToolbar("l-bar-btnad", "l-icon-config", addAd,"添加广告信息");
                    appendModifyBtn(openModify, "修改商户信息");
                    appendDeleteBtn(deleteRow, "删除商户信息");
                $("#pageloading").hide();
                //默认查询全部数据 
                toQuery();
                
            });
            //新增
            function openDictDef() {
            	addDialog = $.ligerDialog.open({height:500,width:700,isResize:true,url:'./add_shop_basic_info.html',title:'新增商户信息'});
                return false;
            }
            //编辑
            function openModify() {
                var row = defGrid.getSelectedRow();
                if (!row) {
                    $.ligerDialog.error('请先选择商户记录。','错误');
                    return;
                }
                modifyDialog = $.ligerDialog.open({height:600,width:800,isResize:true,url:'./add_shop_basic_info.html?o=m&code='.concat(row.shop_no),title:'修改商户信息'});
            }
            //添加WIFI
            function addWifi(){
            	 var row = defGrid.getSelectedRow();
                 if (!row) {
                     $.ligerDialog.error('请先选择商户记录。','错误');
                     return;
                 }
                 parent.f_addTab('add_wifi_info','新增WIFI信息','./wifiInfo/add_wifi_info.html?o=s&code='.concat(row.shop_no));
             }
            //添加广告
            function addAd(){
                var row = defGrid.getSelectedRow();
                if (!row) {
                    $.ligerDialog.error('请先选择商户记录。','错误');
                    return;
                }
                parent.f_addTab('add_adertise_info','新增广告信息','./wifiInfo/add_adertise_info.html?o=s&code='.concat(row.shop_no));
            }
            // 审核确认
            function toConfirm(rowid) {
                var row = defGrid.getRow(rowid);
                var param=new Object();
                    param.shop_no=row.shop_no;
                    param.shop_useable="1";
                    upPickingDel(param,'审核成功','审核失败');
                }           
            //订单计划的审核状态的修改
            function upPickingDel(param,successInfo,errorInfo){
                 var param = JSON.stringify(reqObj('u','wifi.update.shop_basic_info.state',JSON.stringify(param)));
                    ajaxSubmit("/cmwifi/rbac/cm.do?m=u", param, function(data) {
                        if (data) {
                            if (parseInt(data['status']) > 0) { 
                                
                                $.ligerDialog.success(successInfo);
                                //自动刷新
                                toQuery();
                            } else {                                
                                $.ligerDialog.error(errorInfo);
                            }
                        }
                    });
            }

            //删除处理 
             function deleteRow(rowid) {
                 var row = defGrid.getSelectedRow();
                  if (!row) {
                    $.ligerDialog.error('请先选择要删除的商户记录。','错误');
                    return;
                   }                
                    $.ligerDialog.confirm('您确定要删除该项数据吗？', function(r) {
                        if (!r)
                            return;
                         toDel(JSON.stringify(row));
                        defGrid.deleteRow(rowid);
                    })
                }
             // 删除处理业务处理
             function toDel(row) {
                 var param = JSON.stringify(reqObj('d','wifi.delete.adertise_delete',row));
                    ajaxSubmit("/cmwifi/rbac/cm.do?m=d", param, function(data) {
                        if (data) {
                            if (parseInt(data['status']) > 0) {
                                var param = JSON.stringify(reqObj('d','wifi.delete.wifi_delete',row));
                                ajaxSubmit("/cmwifi/rbac/cm.do?m=d", param, function(data) {
                                    if (data) {
                                        if (parseInt(data['status']) > 0) {
                                        	var param = JSON.stringify(reqObj('d','wifi.delete.shop_basic_info.delete',row));
                                            ajaxSubmit("/cmwifi/rbac/cm.do?m=d", param, function(data) {
                                                if (data) {
                                                    if (parseInt(data['status']) > 0) {
                                                       toQuery();
                                                       $.ligerDialog.success('删除成功');
                                                    } else {
                                                        $.ligerDialog.error('删除失败');
                                                    }
                                                }
                                            });
                                        } else {
                                            $.ligerDialog.error('删除失败');
                                        }
                                    }
                                });
                            } else {
                                $.ligerDialog.error('删除失败');
                            }
                        }
                    });
            }
                //通用单据查询 界面
                function searchRow(){
                    var row = defGrid.getSelectedRow();

                    if (!row) {
                        $.ligerDialog.error('请先选择要查看的单据！','错误');
                        return;
                    }
                    var stockDelID=row.pdc_plan_code;
                    parent.f_addTab('new_search_productionS'+stockDelID,'单据明细信息('+stockDelID+')','./production/query_production_plan.html?o=m&code='.concat(row.pdc_plan_code));
                }
                
                //查询订单计划编号信息
                function toQuery(item, page, pageSize) {
                    if (!page)
                        page = defGrid.options.page;
                    if (!pageSize)
                        pageSize = defGrid.options.pageSize;
                    var param = new Object();
                    param.shop_name = $("#shop_nameQ").val();
                    param.shop_no=$("#shop_noQ").val();
                    param.shop_useable=$("#stateQ").val();
                    var data = JSON.stringify(reqObj('q','wifi.select.shop_basic_info.query',JSON.stringify(param),'l',true,page,pageSize));
                    ajaxSubmit("/cmwifi/rbac/cm.do?m=c", data, function(data) {
                         //增加分页信息 start 
                        var d = data['data'].Rows;
                        var ps = defGrid.options.pageSize, p = defGrid.options.page, t = parseInt(data['data'].Total);
                        if (t > ps) {
                            for (var i = 0; i < (p - 1) * ps; i++) {
                                d.unshift(null);
                            }
                        }
                        defGrid.data = data['data'];
                         //增加分页信息  end 
                        defGrid.set({data: data['data']});
                    });
                }
                //密码修改窗口
                function open_Modfiy_PW(rowid) {
                    shopNo = defGrid.getRow(rowid)['shop_no'];
                    if (shopNo) {
                        toReset('#new_dict_def input,select,textarea');
                        addDialog = $.ligerDialog.open({
                            target:$("#new_dict_def"),
                            title:"密码修改",
                            width:400,
                            height:200
                        });
                    }
                }

                //修改密码时，两次密码一致性校验。不一致时，弹出窗口
                function toupdatepw()
                {  
                    var pwd1=$("#password1").val();
                    var pwd2=$("#password2").val();
                    if(pwd1!=pwd2)
                    {
                        $.ligerDialog.success('两次密码不一致请重新输入！');
                        return;
                    }
                    var parampw = new Object();
                    parampw.shop_no=shopNo;
                    parampw.shop_pwd =hex_md5(pwd1).toUpperCase() ;
                    
                    var param = JSON.stringify(reqObj('u','wifi.update.shop_basic_info.update_pwd',JSON.stringify(parampw)));
                    
                    ajaxSubmit("/cmwifi/rbac/cm.do?m=u", param, function(data) {
                    if (data) {
                        if (parseInt(data['status']) > 0) {
                            $.ligerDialog.success('保存成功');
                            addDialog.hide();
                        } else {
                            $.ligerDialog.error('保存失败');
                        }
                    }
                });}
        </script>
        <style type="text/css">
            label{margin: 5px 20px 5px 15px;}
            .fields{height:35px;padding-top:5px;}
            .dict-info{width: 260px;padding: 10px;}
            .diff {margin:3px 0;}
            .lineD {width:99%;float:left;position:relative;overflow:hidden;margin:10px 0 2px 2px}
            .labelD {width:26%;position:relative;float:left;padding-top:3px;}
            .dplD {width:73%;position:relative;float:left;}
            .title{font-size:14px;font-weight:bold;background-position:left;padding-left:18px;}
        </style>
    </head>
    <body style="padding:0;">
        <div id="pageloading"></div>  
        <input type="hidden" id="createUserCodeS" />
        <div id="layout_main">
            <div position="center" id="a_center" title="商户信息管理">
                <div id="query_cond" class="fields">
                     <label>商户名称</label><input type="text" class="s-text-qCond txt-def" id="shop_nameQ" />
                     <label>商户账号</label><input type="text" class="s-text-qCond txt-def" id="shop_noQ" />
                     <label>审核状态</label><select id="stateQ" param="shop.status" first="" ></select>
                    <input type="button" value="查询" style="margin-left:25px;" onclick="toQuery();" />
                    <input type="button" value="清空" onclick="toReset('#query_cond input,select,textarea');" />
                </div>
                <div id="query_list"></div>
            </div>
        </div>
         <div id="new_dict_def" style="display:none;overflow:hidden;">
            <div class="line-div">
                <div class="labelD"><label>新密码</label></div>
                <div class="dplD"><input type="password" class="s-text txt-def" id="password1" /></div>
            </div>
        <div class="line-div">
                <div class="labelD"><label>确认密码</label></div>
                <div class="dplD"><input type="password" class="s-text txt-def" id="password2" /></div>
            </div>
            <div class="line-div" style="margin-top:15px;padding-left:30%;">
               <div class="line-div">
                <input type="button" value="保存" onclick="toupdatepw();" />
                <input type="button" value="清空" onclick="toReset('#up_dict_pw input,select,textarea')" />
            </div>
           
        </div>
    </body>
</html>